package IOStream;

/*
 * Author: JacksonCoder
 * FileName: ByteStreamCopyFile
 * Version: 1.0.0
 * Date: 2025/2/25
 */

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class ByteStreamCopyFile {

    public static void main(String[] args) {
        String sourceFilePath = "source.txt"; // 源文件
        String destinationFilePath = "destination.txt"; // 目标文件路径

        // 使用 try-with-resources 自动关闭流
        try (FileInputStream fis = new FileInputStream(sourceFilePath);
             FileOutputStream fos = new FileOutputStream(destinationFilePath)) {

            byte[] buffer = new byte[1024];
            int bytesRead;

            // 从输入流读取数据并写入输出流
            while ((bytesRead = fis.read(buffer)) != -1) {
                fos.write(buffer, 0, bytesRead);
            }
            System.out.println("文件复制完毕");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}